import json
from venv import logger
from rest_framework.views import APIView
from rest_framework import status, permissions
from ..models import Bot, Conversation, BotPublishHistory
from ..serializers import BotSerializer, ConversationSerializer
import requests  # type: ignore
from django.conf import settings  # 引入 settings

from ..services.prompt_service import PromptGenerationService
from .BaseResponse import BaseResponse

class BotRetrieveView(APIView):
    permission_classes = [permissions.IsAuthenticated]  # 确保用户已登录

    def get(self, request, bot_id):
        # 获取指定智能体
        try:
            bot = Bot.objects.get(bot_id=bot_id, user=request.user)
            serializer = BotSerializer(bot)
            return BaseResponse.success(serializer.data)
        except Bot.DoesNotExist:
            return BaseResponse.error("Bot not found", status=status.HTTP_404_NOT_FOUND)